package cn.zptc.springbootdemo.component;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

//@WebListener
//@Component
public class MyListener implements ServletContextListener, HttpSessionListener, HttpSessionAttributeListener {

    public MyListener() {
    }

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println(" /* This method is called when the servlet context is initialized(when the Web application is deployed). */");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("/* This method is called when the servlet Context is undeployed or Application Server shuts down. */");
    }

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.out.println("/* Session is created. */");
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        System.out.println("/* Session is destroyed. */");
    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent sbe) {
        System.out.println("/* This method is called when an attribute is added to a session. */");
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent sbe) {
        System.out.println("/* This method is called when an attribute is removed from a session. */");
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent sbe) {
        System.out.println("/* This method is called when an attribute is replaced in a session. */");
    }
}
